﻿using System;
using System.Data.SqlClient;

namespace Yglu.BusinessLayer.Entities
{
	public class ComboCollection : BaseEntityCollection
	{
		#region Extra properties

		public Double TotalPrice
		{
			get
			{
				Double price = 0;

				foreach (Combo c in this)
				{
					price += c.TotalPrice;
				}

				return price;
			}
		}

		public Double PriceWithDiscount
		{
			get
			{
				Double price = 0;

				foreach (Combo c in this)
				{
					price += c.PriceWithDiscount;
				}

				return price;
			}
		}

		#endregion

		#region Constructor

		public ComboCollection()
		{
		}

		public ComboCollection(SqlDataReader reader)
		{
			Load(reader);
		}

		#endregion

		#region Loading

		public override sealed void Load(SqlDataReader reader)
		{
			if (Count > 0)
			{
				Clear();
			}

			while (reader.Read())
			{
				Combo c = new Combo();
				c.Load(reader);

				Add(c);
			}

			if (!reader.IsClosed)
			{
				reader.Close();
			}

			reader.Dispose();
		}

		#endregion
	}
}